import { ComponentWithStore } from 'mobx-miniprogram-bindings'
import { InfoStore } from '@/stores/InfoStore'
import { reqGetInfo, reqIsRegister } from '@/api/user'
import { setStorage } from '@/utils/storage'
ComponentWithStore({
  data: {
    // 是否报名
    isSubmit: false,
    userInfo: ''
  },
  storeBindings: {
    store: InfoStore,
    fields: ['isRegister', 'userInfo'],
    actions: ['setUserInfo', 'setisRegister']
  },
  methods: {
    onLoad() {
      this.setData({
        isSubmit: this.data.isRegister,
        userInfo: this.data.userInfo
      })
    },
    onShow() {
      this.setData({
        isSubmit: this.data.isRegister,
        userInfo: this.data.userInfo
      })
    },
    async getSubmit(event) {
      const {
        data
      } = await reqGetInfo()

      setStorage('userInfo', data)

      setStorage('isRegister', true)

      this.setUserInfo(data)

      this.setisRegister(true)

      this.setData({
        isSubmit: event.detail,
        userInfo: data
      })

    }
  }
})